{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>policy_id</th>\n",
       "      <th>age</th>\n",
       "      <th>customer_months</th>\n",
       "      <th>policy_bind_date</th>\n",
       "      <th>policy_state</th>\n",
       "      <th>policy_csl</th>\n",
       "      <th>policy_deductable</th>\n",
       "      <th>policy_annual_premium</th>\n",
       "      <th>umbrella_limit</th>\n",
       "      <th>insured_zip</th>\n",
       "      <th>...</th>\n",
       "      <th>witnesses</th>\n",
       "      <th>police_report_available</th>\n",
       "      <th>total_claim_amount</th>\n",
       "      <th>injury_claim</th>\n",
       "      <th>property_claim</th>\n",
       "      <th>vehicle_claim</th>\n",
       "      <th>auto_make</th>\n",
       "      <th>auto_model</th>\n",
       "      <th>auto_year</th>\n",
       "      <th>fraud</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>122576</td>\n",
       "      <td>37</td>\n",
       "      <td>189</td>\n",
       "      <td>2013-08-21</td>\n",
       "      <td>C</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1465.71</td>\n",
       "      <td>5000000</td>\n",
       "      <td>455456</td>\n",
       "      <td>...</td>\n",
       "      <td>3</td>\n",
       "      <td>?</td>\n",
       "      <td>54930</td>\n",
       "      <td>6029</td>\n",
       "      <td>5752</td>\n",
       "      <td>44452</td>\n",
       "      <td>Nissan</td>\n",
       "      <td>Maxima</td>\n",
       "      <td>2000</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>937713</td>\n",
       "      <td>44</td>\n",
       "      <td>234</td>\n",
       "      <td>1998-01-04</td>\n",
       "      <td>B</td>\n",
       "      <td>250/500</td>\n",
       "      <td>500</td>\n",
       "      <td>821.24</td>\n",
       "      <td>0</td>\n",
       "      <td>591805</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>YES</td>\n",
       "      <td>50680</td>\n",
       "      <td>5376</td>\n",
       "      <td>10156</td>\n",
       "      <td>37347</td>\n",
       "      <td>Honda</td>\n",
       "      <td>Civic</td>\n",
       "      <td>1996</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>680237</td>\n",
       "      <td>33</td>\n",
       "      <td>23</td>\n",
       "      <td>1996-02-06</td>\n",
       "      <td>B</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1844.00</td>\n",
       "      <td>0</td>\n",
       "      <td>442490</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>NO</td>\n",
       "      <td>47829</td>\n",
       "      <td>4460</td>\n",
       "      <td>9247</td>\n",
       "      <td>33644</td>\n",
       "      <td>Jeep</td>\n",
       "      <td>Wrangler</td>\n",
       "      <td>2002</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>513080</td>\n",
       "      <td>42</td>\n",
       "      <td>210</td>\n",
       "      <td>2008-11-14</td>\n",
       "      <td>A</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>500</td>\n",
       "      <td>1867.29</td>\n",
       "      <td>0</td>\n",
       "      <td>439408</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>YES</td>\n",
       "      <td>68862</td>\n",
       "      <td>11043</td>\n",
       "      <td>5955</td>\n",
       "      <td>53548</td>\n",
       "      <td>Suburu</td>\n",
       "      <td>Legacy</td>\n",
       "      <td>2003</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>192875</td>\n",
       "      <td>29</td>\n",
       "      <td>81</td>\n",
       "      <td>2002-01-08</td>\n",
       "      <td>A</td>\n",
       "      <td>100/300</td>\n",
       "      <td>1000</td>\n",
       "      <td>816.25</td>\n",
       "      <td>0</td>\n",
       "      <td>640575</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>YES</td>\n",
       "      <td>59726</td>\n",
       "      <td>5617</td>\n",
       "      <td>10301</td>\n",
       "      <td>41550</td>\n",
       "      <td>Ford</td>\n",
       "      <td>F150</td>\n",
       "      <td>2004</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 38 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   policy_id  age  customer_months policy_bind_date policy_state policy_csl  \\\n",
       "0     122576   37              189       2013-08-21            C   500/1000   \n",
       "1     937713   44              234       1998-01-04            B    250/500   \n",
       "2     680237   33               23       1996-02-06            B   500/1000   \n",
       "3     513080   42              210       2008-11-14            A   500/1000   \n",
       "4     192875   29               81       2002-01-08            A    100/300   \n",
       "\n",
       "   policy_deductable  policy_annual_premium  umbrella_limit  insured_zip  ...  \\\n",
       "0               1000                1465.71         5000000       455456  ...   \n",
       "1                500                 821.24               0       591805  ...   \n",
       "2               1000                1844.00               0       442490  ...   \n",
       "3                500                1867.29               0       439408  ...   \n",
       "4               1000                 816.25               0       640575  ...   \n",
       "\n",
       "  witnesses police_report_available total_claim_amount injury_claim  \\\n",
       "0         3                       ?              54930         6029   \n",
       "1         1                     YES              50680         5376   \n",
       "2         1                      NO              47829         4460   \n",
       "3         2                     YES              68862        11043   \n",
       "4         1                     YES              59726         5617   \n",
       "\n",
       "  property_claim  vehicle_claim  auto_make auto_model auto_year fraud  \n",
       "0           5752          44452     Nissan     Maxima      2000     0  \n",
       "1          10156          37347      Honda      Civic      1996     0  \n",
       "2           9247          33644       Jeep   Wrangler      2002     0  \n",
       "3           5955          53548     Suburu     Legacy      2003     1  \n",
       "4          10301          41550       Ford       F150      2004     0  \n",
       "\n",
       "[5 rows x 38 columns]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "train = pd.read_csv('./tianchi-dataset/train.csv')\n",
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>policy_id</th>\n",
       "      <th>age</th>\n",
       "      <th>customer_months</th>\n",
       "      <th>policy_bind_date</th>\n",
       "      <th>policy_state</th>\n",
       "      <th>policy_csl</th>\n",
       "      <th>policy_deductable</th>\n",
       "      <th>policy_annual_premium</th>\n",
       "      <th>umbrella_limit</th>\n",
       "      <th>insured_zip</th>\n",
       "      <th>...</th>\n",
       "      <th>bodily_injuries</th>\n",
       "      <th>witnesses</th>\n",
       "      <th>police_report_available</th>\n",
       "      <th>total_claim_amount</th>\n",
       "      <th>injury_claim</th>\n",
       "      <th>property_claim</th>\n",
       "      <th>vehicle_claim</th>\n",
       "      <th>auto_make</th>\n",
       "      <th>auto_model</th>\n",
       "      <th>auto_year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>681822</td>\n",
       "      <td>60</td>\n",
       "      <td>473</td>\n",
       "      <td>2002-12-17</td>\n",
       "      <td>B</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1134.96</td>\n",
       "      <td>0</td>\n",
       "      <td>445975</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>?</td>\n",
       "      <td>53253</td>\n",
       "      <td>5212</td>\n",
       "      <td>10251</td>\n",
       "      <td>39503</td>\n",
       "      <td>Saab</td>\n",
       "      <td>95</td>\n",
       "      <td>2006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>301288</td>\n",
       "      <td>36</td>\n",
       "      <td>173</td>\n",
       "      <td>1994-01-15</td>\n",
       "      <td>B</td>\n",
       "      <td>100/300</td>\n",
       "      <td>1000</td>\n",
       "      <td>916.20</td>\n",
       "      <td>0</td>\n",
       "      <td>469238</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NO</td>\n",
       "      <td>69401</td>\n",
       "      <td>8309</td>\n",
       "      <td>8439</td>\n",
       "      <td>50012</td>\n",
       "      <td>Mercedes</td>\n",
       "      <td>ML350</td>\n",
       "      <td>2008</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>212001</td>\n",
       "      <td>36</td>\n",
       "      <td>147</td>\n",
       "      <td>1995-12-19</td>\n",
       "      <td>B</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1175.74</td>\n",
       "      <td>5000000</td>\n",
       "      <td>595953</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>NO</td>\n",
       "      <td>63919</td>\n",
       "      <td>5572</td>\n",
       "      <td>11477</td>\n",
       "      <td>42801</td>\n",
       "      <td>Dodge</td>\n",
       "      <td>Neon</td>\n",
       "      <td>2009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>797680</td>\n",
       "      <td>24</td>\n",
       "      <td>71</td>\n",
       "      <td>1992-06-20</td>\n",
       "      <td>C</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>500</td>\n",
       "      <td>1472.40</td>\n",
       "      <td>0</td>\n",
       "      <td>613103</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NO</td>\n",
       "      <td>63173</td>\n",
       "      <td>12027</td>\n",
       "      <td>6500</td>\n",
       "      <td>43423</td>\n",
       "      <td>Dodge</td>\n",
       "      <td>RAM</td>\n",
       "      <td>2012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>789334</td>\n",
       "      <td>39</td>\n",
       "      <td>230</td>\n",
       "      <td>1996-11-28</td>\n",
       "      <td>C</td>\n",
       "      <td>250/500</td>\n",
       "      <td>1000</td>\n",
       "      <td>1159.44</td>\n",
       "      <td>4000000</td>\n",
       "      <td>581581</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>?</td>\n",
       "      <td>8847</td>\n",
       "      <td>904</td>\n",
       "      <td>1786</td>\n",
       "      <td>6138</td>\n",
       "      <td>Accura</td>\n",
       "      <td>RSX</td>\n",
       "      <td>2003</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 37 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   policy_id  age  customer_months policy_bind_date policy_state policy_csl  \\\n",
       "0     681822   60              473       2002-12-17            B   500/1000   \n",
       "1     301288   36              173       1994-01-15            B    100/300   \n",
       "2     212001   36              147       1995-12-19            B   500/1000   \n",
       "3     797680   24               71       1992-06-20            C   500/1000   \n",
       "4     789334   39              230       1996-11-28            C    250/500   \n",
       "\n",
       "   policy_deductable  policy_annual_premium  umbrella_limit  insured_zip  ...  \\\n",
       "0               1000                1134.96               0       445975  ...   \n",
       "1               1000                 916.20               0       469238  ...   \n",
       "2               1000                1175.74         5000000       595953  ...   \n",
       "3                500                1472.40               0       613103  ...   \n",
       "4               1000                1159.44         4000000       581581  ...   \n",
       "\n",
       "  bodily_injuries witnesses police_report_available total_claim_amount  \\\n",
       "0               0         3                       ?              53253   \n",
       "1               0         0                      NO              69401   \n",
       "2               2         0                      NO              63919   \n",
       "3               0         0                      NO              63173   \n",
       "4               0         0                       ?               8847   \n",
       "\n",
       "  injury_claim  property_claim  vehicle_claim auto_make auto_model auto_year  \n",
       "0         5212           10251          39503      Saab         95      2006  \n",
       "1         8309            8439          50012  Mercedes      ML350      2008  \n",
       "2         5572           11477          42801     Dodge       Neon      2009  \n",
       "3        12027            6500          43423     Dodge        RAM      2012  \n",
       "4          904            1786           6138    Accura        RSX      2003  \n",
       "\n",
       "[5 rows x 37 columns]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test = pd.read_csv('./tianchi-dataset/test.csv')\n",
    "test.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>policy_id</th>\n",
       "      <th>age</th>\n",
       "      <th>customer_months</th>\n",
       "      <th>policy_bind_date</th>\n",
       "      <th>policy_state</th>\n",
       "      <th>policy_csl</th>\n",
       "      <th>policy_deductable</th>\n",
       "      <th>policy_annual_premium</th>\n",
       "      <th>umbrella_limit</th>\n",
       "      <th>insured_zip</th>\n",
       "      <th>...</th>\n",
       "      <th>witnesses</th>\n",
       "      <th>police_report_available</th>\n",
       "      <th>total_claim_amount</th>\n",
       "      <th>injury_claim</th>\n",
       "      <th>property_claim</th>\n",
       "      <th>vehicle_claim</th>\n",
       "      <th>auto_make</th>\n",
       "      <th>auto_model</th>\n",
       "      <th>auto_year</th>\n",
       "      <th>fraud</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>122576</td>\n",
       "      <td>37</td>\n",
       "      <td>189</td>\n",
       "      <td>2013-08-21</td>\n",
       "      <td>C</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1465.71</td>\n",
       "      <td>5000000</td>\n",
       "      <td>455456</td>\n",
       "      <td>...</td>\n",
       "      <td>3</td>\n",
       "      <td>?</td>\n",
       "      <td>54930</td>\n",
       "      <td>6029</td>\n",
       "      <td>5752</td>\n",
       "      <td>44452</td>\n",
       "      <td>Nissan</td>\n",
       "      <td>Maxima</td>\n",
       "      <td>2000</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>937713</td>\n",
       "      <td>44</td>\n",
       "      <td>234</td>\n",
       "      <td>1998-01-04</td>\n",
       "      <td>B</td>\n",
       "      <td>250/500</td>\n",
       "      <td>500</td>\n",
       "      <td>821.24</td>\n",
       "      <td>0</td>\n",
       "      <td>591805</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>YES</td>\n",
       "      <td>50680</td>\n",
       "      <td>5376</td>\n",
       "      <td>10156</td>\n",
       "      <td>37347</td>\n",
       "      <td>Honda</td>\n",
       "      <td>Civic</td>\n",
       "      <td>1996</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>680237</td>\n",
       "      <td>33</td>\n",
       "      <td>23</td>\n",
       "      <td>1996-02-06</td>\n",
       "      <td>B</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1844.00</td>\n",
       "      <td>0</td>\n",
       "      <td>442490</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>NO</td>\n",
       "      <td>47829</td>\n",
       "      <td>4460</td>\n",
       "      <td>9247</td>\n",
       "      <td>33644</td>\n",
       "      <td>Jeep</td>\n",
       "      <td>Wrangler</td>\n",
       "      <td>2002</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>513080</td>\n",
       "      <td>42</td>\n",
       "      <td>210</td>\n",
       "      <td>2008-11-14</td>\n",
       "      <td>A</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>500</td>\n",
       "      <td>1867.29</td>\n",
       "      <td>0</td>\n",
       "      <td>439408</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>YES</td>\n",
       "      <td>68862</td>\n",
       "      <td>11043</td>\n",
       "      <td>5955</td>\n",
       "      <td>53548</td>\n",
       "      <td>Suburu</td>\n",
       "      <td>Legacy</td>\n",
       "      <td>2003</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>192875</td>\n",
       "      <td>29</td>\n",
       "      <td>81</td>\n",
       "      <td>2002-01-08</td>\n",
       "      <td>A</td>\n",
       "      <td>100/300</td>\n",
       "      <td>1000</td>\n",
       "      <td>816.25</td>\n",
       "      <td>0</td>\n",
       "      <td>640575</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>YES</td>\n",
       "      <td>59726</td>\n",
       "      <td>5617</td>\n",
       "      <td>10301</td>\n",
       "      <td>41550</td>\n",
       "      <td>Ford</td>\n",
       "      <td>F150</td>\n",
       "      <td>2004</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>295</th>\n",
       "      <td>663065</td>\n",
       "      <td>36</td>\n",
       "      <td>30</td>\n",
       "      <td>1999-08-18</td>\n",
       "      <td>B</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>2000</td>\n",
       "      <td>1384.15</td>\n",
       "      <td>9000000</td>\n",
       "      <td>593323</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>YES</td>\n",
       "      <td>4507</td>\n",
       "      <td>970</td>\n",
       "      <td>477</td>\n",
       "      <td>3339</td>\n",
       "      <td>Dodge</td>\n",
       "      <td>Neon</td>\n",
       "      <td>2002</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>296</th>\n",
       "      <td>283767</td>\n",
       "      <td>47</td>\n",
       "      <td>285</td>\n",
       "      <td>2009-12-23</td>\n",
       "      <td>C</td>\n",
       "      <td>250/500</td>\n",
       "      <td>500</td>\n",
       "      <td>1590.78</td>\n",
       "      <td>7000000</td>\n",
       "      <td>447235</td>\n",
       "      <td>...</td>\n",
       "      <td>3</td>\n",
       "      <td>YES</td>\n",
       "      <td>45909</td>\n",
       "      <td>5599</td>\n",
       "      <td>5627</td>\n",
       "      <td>34598</td>\n",
       "      <td>Jeep</td>\n",
       "      <td>Grand Cherokee</td>\n",
       "      <td>1999</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>297</th>\n",
       "      <td>325099</td>\n",
       "      <td>39</td>\n",
       "      <td>256</td>\n",
       "      <td>1999-04-08</td>\n",
       "      <td>C</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>2000</td>\n",
       "      <td>1265.24</td>\n",
       "      <td>0</td>\n",
       "      <td>592069</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>?</td>\n",
       "      <td>42293</td>\n",
       "      <td>5773</td>\n",
       "      <td>5491</td>\n",
       "      <td>34805</td>\n",
       "      <td>Dodge</td>\n",
       "      <td>RAM</td>\n",
       "      <td>1997</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>298</th>\n",
       "      <td>465673</td>\n",
       "      <td>35</td>\n",
       "      <td>54</td>\n",
       "      <td>2010-09-08</td>\n",
       "      <td>C</td>\n",
       "      <td>100/300</td>\n",
       "      <td>500</td>\n",
       "      <td>1229.74</td>\n",
       "      <td>0</td>\n",
       "      <td>451451</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>?</td>\n",
       "      <td>76875</td>\n",
       "      <td>14955</td>\n",
       "      <td>7312</td>\n",
       "      <td>59418</td>\n",
       "      <td>Nissan</td>\n",
       "      <td>Maxima</td>\n",
       "      <td>2012</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>299</th>\n",
       "      <td>913900</td>\n",
       "      <td>34</td>\n",
       "      <td>154</td>\n",
       "      <td>1990-09-27</td>\n",
       "      <td>C</td>\n",
       "      <td>100/300</td>\n",
       "      <td>500</td>\n",
       "      <td>1744.33</td>\n",
       "      <td>0</td>\n",
       "      <td>462941</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>YES</td>\n",
       "      <td>76269</td>\n",
       "      <td>8260</td>\n",
       "      <td>8354</td>\n",
       "      <td>59141</td>\n",
       "      <td>Honda</td>\n",
       "      <td>Civic</td>\n",
       "      <td>1998</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 38 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     policy_id  age  customer_months policy_bind_date policy_state policy_csl  \\\n",
       "0       122576   37              189       2013-08-21            C   500/1000   \n",
       "1       937713   44              234       1998-01-04            B    250/500   \n",
       "2       680237   33               23       1996-02-06            B   500/1000   \n",
       "3       513080   42              210       2008-11-14            A   500/1000   \n",
       "4       192875   29               81       2002-01-08            A    100/300   \n",
       "..         ...  ...              ...              ...          ...        ...   \n",
       "295     663065   36               30       1999-08-18            B   500/1000   \n",
       "296     283767   47              285       2009-12-23            C    250/500   \n",
       "297     325099   39              256       1999-04-08            C   500/1000   \n",
       "298     465673   35               54       2010-09-08            C    100/300   \n",
       "299     913900   34              154       1990-09-27            C    100/300   \n",
       "\n",
       "     policy_deductable  policy_annual_premium  umbrella_limit  insured_zip  \\\n",
       "0                 1000                1465.71         5000000       455456   \n",
       "1                  500                 821.24               0       591805   \n",
       "2                 1000                1844.00               0       442490   \n",
       "3                  500                1867.29               0       439408   \n",
       "4                 1000                 816.25               0       640575   \n",
       "..                 ...                    ...             ...          ...   \n",
       "295               2000                1384.15         9000000       593323   \n",
       "296                500                1590.78         7000000       447235   \n",
       "297               2000                1265.24               0       592069   \n",
       "298                500                1229.74               0       451451   \n",
       "299                500                1744.33               0       462941   \n",
       "\n",
       "     ... witnesses police_report_available total_claim_amount injury_claim  \\\n",
       "0    ...         3                       ?              54930         6029   \n",
       "1    ...         1                     YES              50680         5376   \n",
       "2    ...         1                      NO              47829         4460   \n",
       "3    ...         2                     YES              68862        11043   \n",
       "4    ...         1                     YES              59726         5617   \n",
       "..   ...       ...                     ...                ...          ...   \n",
       "295  ...         1                     YES               4507          970   \n",
       "296  ...         3                     YES              45909         5599   \n",
       "297  ...         0                       ?              42293         5773   \n",
       "298  ...         0                       ?              76875        14955   \n",
       "299  ...         1                     YES              76269         8260   \n",
       "\n",
       "    property_claim  vehicle_claim  auto_make      auto_model auto_year fraud  \n",
       "0             5752          44452     Nissan          Maxima      2000   0.0  \n",
       "1            10156          37347      Honda           Civic      1996   0.0  \n",
       "2             9247          33644       Jeep        Wrangler      2002   0.0  \n",
       "3             5955          53548     Suburu          Legacy      2003   1.0  \n",
       "4            10301          41550       Ford            F150      2004   0.0  \n",
       "..             ...            ...        ...             ...       ...   ...  \n",
       "295            477           3339      Dodge            Neon      2002   NaN  \n",
       "296           5627          34598       Jeep  Grand Cherokee      1999   NaN  \n",
       "297           5491          34805      Dodge             RAM      1997   NaN  \n",
       "298           7312          59418     Nissan          Maxima      2012   NaN  \n",
       "299           8354          59141      Honda           Civic      1998   NaN  \n",
       "\n",
       "[1000 rows x 38 columns]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = pd.concat([train, test], axis=0)\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>policy_id</th>\n",
       "      <th>age</th>\n",
       "      <th>customer_months</th>\n",
       "      <th>policy_bind_date</th>\n",
       "      <th>policy_state</th>\n",
       "      <th>policy_csl</th>\n",
       "      <th>policy_deductable</th>\n",
       "      <th>policy_annual_premium</th>\n",
       "      <th>umbrella_limit</th>\n",
       "      <th>insured_zip</th>\n",
       "      <th>...</th>\n",
       "      <th>witnesses</th>\n",
       "      <th>police_report_available</th>\n",
       "      <th>total_claim_amount</th>\n",
       "      <th>injury_claim</th>\n",
       "      <th>property_claim</th>\n",
       "      <th>vehicle_claim</th>\n",
       "      <th>auto_make</th>\n",
       "      <th>auto_model</th>\n",
       "      <th>auto_year</th>\n",
       "      <th>fraud</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>122576</td>\n",
       "      <td>37</td>\n",
       "      <td>189</td>\n",
       "      <td>2013-08-21</td>\n",
       "      <td>C</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1465.71</td>\n",
       "      <td>5000000</td>\n",
       "      <td>455456</td>\n",
       "      <td>...</td>\n",
       "      <td>3</td>\n",
       "      <td>?</td>\n",
       "      <td>54930</td>\n",
       "      <td>6029</td>\n",
       "      <td>5752</td>\n",
       "      <td>44452</td>\n",
       "      <td>Nissan</td>\n",
       "      <td>Maxima</td>\n",
       "      <td>2000</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>937713</td>\n",
       "      <td>44</td>\n",
       "      <td>234</td>\n",
       "      <td>1998-01-04</td>\n",
       "      <td>B</td>\n",
       "      <td>250/500</td>\n",
       "      <td>500</td>\n",
       "      <td>821.24</td>\n",
       "      <td>0</td>\n",
       "      <td>591805</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>YES</td>\n",
       "      <td>50680</td>\n",
       "      <td>5376</td>\n",
       "      <td>10156</td>\n",
       "      <td>37347</td>\n",
       "      <td>Honda</td>\n",
       "      <td>Civic</td>\n",
       "      <td>1996</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>680237</td>\n",
       "      <td>33</td>\n",
       "      <td>23</td>\n",
       "      <td>1996-02-06</td>\n",
       "      <td>B</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>1000</td>\n",
       "      <td>1844.00</td>\n",
       "      <td>0</td>\n",
       "      <td>442490</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>NO</td>\n",
       "      <td>47829</td>\n",
       "      <td>4460</td>\n",
       "      <td>9247</td>\n",
       "      <td>33644</td>\n",
       "      <td>Jeep</td>\n",
       "      <td>Wrangler</td>\n",
       "      <td>2002</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>513080</td>\n",
       "      <td>42</td>\n",
       "      <td>210</td>\n",
       "      <td>2008-11-14</td>\n",
       "      <td>A</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>500</td>\n",
       "      <td>1867.29</td>\n",
       "      <td>0</td>\n",
       "      <td>439408</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>YES</td>\n",
       "      <td>68862</td>\n",
       "      <td>11043</td>\n",
       "      <td>5955</td>\n",
       "      <td>53548</td>\n",
       "      <td>Suburu</td>\n",
       "      <td>Legacy</td>\n",
       "      <td>2003</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>192875</td>\n",
       "      <td>29</td>\n",
       "      <td>81</td>\n",
       "      <td>2002-01-08</td>\n",
       "      <td>A</td>\n",
       "      <td>100/300</td>\n",
       "      <td>1000</td>\n",
       "      <td>816.25</td>\n",
       "      <td>0</td>\n",
       "      <td>640575</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>YES</td>\n",
       "      <td>59726</td>\n",
       "      <td>5617</td>\n",
       "      <td>10301</td>\n",
       "      <td>41550</td>\n",
       "      <td>Ford</td>\n",
       "      <td>F150</td>\n",
       "      <td>2004</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>663065</td>\n",
       "      <td>36</td>\n",
       "      <td>30</td>\n",
       "      <td>1999-08-18</td>\n",
       "      <td>B</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>2000</td>\n",
       "      <td>1384.15</td>\n",
       "      <td>9000000</td>\n",
       "      <td>593323</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>YES</td>\n",
       "      <td>4507</td>\n",
       "      <td>970</td>\n",
       "      <td>477</td>\n",
       "      <td>3339</td>\n",
       "      <td>Dodge</td>\n",
       "      <td>Neon</td>\n",
       "      <td>2002</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>283767</td>\n",
       "      <td>47</td>\n",
       "      <td>285</td>\n",
       "      <td>2009-12-23</td>\n",
       "      <td>C</td>\n",
       "      <td>250/500</td>\n",
       "      <td>500</td>\n",
       "      <td>1590.78</td>\n",
       "      <td>7000000</td>\n",
       "      <td>447235</td>\n",
       "      <td>...</td>\n",
       "      <td>3</td>\n",
       "      <td>YES</td>\n",
       "      <td>45909</td>\n",
       "      <td>5599</td>\n",
       "      <td>5627</td>\n",
       "      <td>34598</td>\n",
       "      <td>Jeep</td>\n",
       "      <td>Grand Cherokee</td>\n",
       "      <td>1999</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>325099</td>\n",
       "      <td>39</td>\n",
       "      <td>256</td>\n",
       "      <td>1999-04-08</td>\n",
       "      <td>C</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>2000</td>\n",
       "      <td>1265.24</td>\n",
       "      <td>0</td>\n",
       "      <td>592069</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>?</td>\n",
       "      <td>42293</td>\n",
       "      <td>5773</td>\n",
       "      <td>5491</td>\n",
       "      <td>34805</td>\n",
       "      <td>Dodge</td>\n",
       "      <td>RAM</td>\n",
       "      <td>1997</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>465673</td>\n",
       "      <td>35</td>\n",
       "      <td>54</td>\n",
       "      <td>2010-09-08</td>\n",
       "      <td>C</td>\n",
       "      <td>100/300</td>\n",
       "      <td>500</td>\n",
       "      <td>1229.74</td>\n",
       "      <td>0</td>\n",
       "      <td>451451</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>?</td>\n",
       "      <td>76875</td>\n",
       "      <td>14955</td>\n",
       "      <td>7312</td>\n",
       "      <td>59418</td>\n",
       "      <td>Nissan</td>\n",
       "      <td>Maxima</td>\n",
       "      <td>2012</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>913900</td>\n",
       "      <td>34</td>\n",
       "      <td>154</td>\n",
       "      <td>1990-09-27</td>\n",
       "      <td>C</td>\n",
       "      <td>100/300</td>\n",
       "      <td>500</td>\n",
       "      <td>1744.33</td>\n",
       "      <td>0</td>\n",
       "      <td>462941</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>YES</td>\n",
       "      <td>76269</td>\n",
       "      <td>8260</td>\n",
       "      <td>8354</td>\n",
       "      <td>59141</td>\n",
       "      <td>Honda</td>\n",
       "      <td>Civic</td>\n",
       "      <td>1998</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 38 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     policy_id  age  customer_months policy_bind_date policy_state policy_csl  \\\n",
       "0       122576   37              189       2013-08-21            C   500/1000   \n",
       "1       937713   44              234       1998-01-04            B    250/500   \n",
       "2       680237   33               23       1996-02-06            B   500/1000   \n",
       "3       513080   42              210       2008-11-14            A   500/1000   \n",
       "4       192875   29               81       2002-01-08            A    100/300   \n",
       "..         ...  ...              ...              ...          ...        ...   \n",
       "995     663065   36               30       1999-08-18            B   500/1000   \n",
       "996     283767   47              285       2009-12-23            C    250/500   \n",
       "997     325099   39              256       1999-04-08            C   500/1000   \n",
       "998     465673   35               54       2010-09-08            C    100/300   \n",
       "999     913900   34              154       1990-09-27            C    100/300   \n",
       "\n",
       "     policy_deductable  policy_annual_premium  umbrella_limit  insured_zip  \\\n",
       "0                 1000                1465.71         5000000       455456   \n",
       "1                  500                 821.24               0       591805   \n",
       "2                 1000                1844.00               0       442490   \n",
       "3                  500                1867.29               0       439408   \n",
       "4                 1000                 816.25               0       640575   \n",
       "..                 ...                    ...             ...          ...   \n",
       "995               2000                1384.15         9000000       593323   \n",
       "996                500                1590.78         7000000       447235   \n",
       "997               2000                1265.24               0       592069   \n",
       "998                500                1229.74               0       451451   \n",
       "999                500                1744.33               0       462941   \n",
       "\n",
       "     ... witnesses police_report_available total_claim_amount injury_claim  \\\n",
       "0    ...         3                       ?              54930         6029   \n",
       "1    ...         1                     YES              50680         5376   \n",
       "2    ...         1                      NO              47829         4460   \n",
       "3    ...         2                     YES              68862        11043   \n",
       "4    ...         1                     YES              59726         5617   \n",
       "..   ...       ...                     ...                ...          ...   \n",
       "995  ...         1                     YES               4507          970   \n",
       "996  ...         3                     YES              45909         5599   \n",
       "997  ...         0                       ?              42293         5773   \n",
       "998  ...         0                       ?              76875        14955   \n",
       "999  ...         1                     YES              76269         8260   \n",
       "\n",
       "    property_claim  vehicle_claim  auto_make      auto_model auto_year fraud  \n",
       "0             5752          44452     Nissan          Maxima      2000   0.0  \n",
       "1            10156          37347      Honda           Civic      1996   0.0  \n",
       "2             9247          33644       Jeep        Wrangler      2002   0.0  \n",
       "3             5955          53548     Suburu          Legacy      2003   1.0  \n",
       "4            10301          41550       Ford            F150      2004   0.0  \n",
       "..             ...            ...        ...             ...       ...   ...  \n",
       "995            477           3339      Dodge            Neon      2002   NaN  \n",
       "996           5627          34598       Jeep  Grand Cherokee      1999   NaN  \n",
       "997           5491          34805      Dodge             RAM      1997   NaN  \n",
       "998           7312          59418     Nissan          Maxima      2012   NaN  \n",
       "999           8354          59141      Honda           Civic      1998   NaN  \n",
       "\n",
       "[1000 rows x 38 columns]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.index = range(data.shape[0])\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "policy_id                        0\n",
       "age                              0\n",
       "customer_months                  0\n",
       "policy_bind_date                 0\n",
       "policy_state                     0\n",
       "policy_csl                       0\n",
       "policy_deductable                0\n",
       "policy_annual_premium            0\n",
       "umbrella_limit                   0\n",
       "insured_zip                      0\n",
       "insured_sex                      0\n",
       "insured_education_level          0\n",
       "insured_occupation               0\n",
       "insured_hobbies                  0\n",
       "insured_relationship             0\n",
       "capital-gains                    0\n",
       "capital-loss                     0\n",
       "incident_date                    0\n",
       "incident_type                    0\n",
       "collision_type                   0\n",
       "incident_severity                0\n",
       "authorities_contacted            0\n",
       "incident_state                   0\n",
       "incident_city                    0\n",
       "incident_hour_of_the_day         0\n",
       "number_of_vehicles_involved      0\n",
       "property_damage                  0\n",
       "bodily_injuries                  0\n",
       "witnesses                        0\n",
       "police_report_available          0\n",
       "total_claim_amount               0\n",
       "injury_claim                     0\n",
       "property_claim                   0\n",
       "vehicle_claim                    0\n",
       "auto_make                        0\n",
       "auto_model                       0\n",
       "auto_year                        0\n",
       "fraud                          300\n",
       "dtype: int64"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数据探索\n",
    "data.isnull().sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col_name</th>\n",
       "      <th>value</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>policy_bind_date</td>\n",
       "      <td>955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>incident_date</td>\n",
       "      <td>113</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>auto_model</td>\n",
       "      <td>39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>insured_hobbies</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>insured_occupation</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>auto_make</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>insured_education_level</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>incident_state</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>incident_city</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>insured_relationship</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>authorities_contacted</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>collision_type</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>incident_severity</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>incident_type</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>policy_csl</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>policy_state</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>property_damage</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>police_report_available</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>insured_sex</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   col_name  value\n",
       "0          policy_bind_date    955\n",
       "8             incident_date    113\n",
       "18               auto_model     39\n",
       "6           insured_hobbies     20\n",
       "5        insured_occupation     14\n",
       "17                auto_make     14\n",
       "4   insured_education_level      7\n",
       "13           incident_state      7\n",
       "14            incident_city      7\n",
       "7      insured_relationship      6\n",
       "12    authorities_contacted      5\n",
       "10           collision_type      4\n",
       "11        incident_severity      4\n",
       "9             incident_type      4\n",
       "2                policy_csl      3\n",
       "1              policy_state      3\n",
       "15          property_damage      3\n",
       "16  police_report_available      3\n",
       "3               insured_sex      2"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "column_name = []\n",
    "unique_value = []\n",
    "cat_columns = data.select_dtypes(include='O').columns\n",
    "for col in cat_columns:\n",
    "    #print(col, data[col].nunique())\n",
    "    column_name.append(col)\n",
    "    unique_value.append(data[col].nunique())\n",
    "\n",
    "df = pd.DataFrame({\n",
    "    'col_name': column_name,\n",
    "    'value': unique_value\n",
    "}).sort_values('value', ascending=False)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>policy_bind_date</th>\n",
       "      <th>policy_state</th>\n",
       "      <th>policy_csl</th>\n",
       "      <th>insured_sex</th>\n",
       "      <th>insured_education_level</th>\n",
       "      <th>insured_occupation</th>\n",
       "      <th>insured_hobbies</th>\n",
       "      <th>insured_relationship</th>\n",
       "      <th>incident_date</th>\n",
       "      <th>incident_type</th>\n",
       "      <th>collision_type</th>\n",
       "      <th>incident_severity</th>\n",
       "      <th>authorities_contacted</th>\n",
       "      <th>incident_state</th>\n",
       "      <th>incident_city</th>\n",
       "      <th>property_damage</th>\n",
       "      <th>police_report_available</th>\n",
       "      <th>auto_make</th>\n",
       "      <th>auto_model</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2013-08-21</td>\n",
       "      <td>C</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>FEMALE</td>\n",
       "      <td>Masters</td>\n",
       "      <td>protective-serv</td>\n",
       "      <td>reading</td>\n",
       "      <td>not-in-family</td>\n",
       "      <td>2014-12-22</td>\n",
       "      <td>Single Vehicle Collision</td>\n",
       "      <td>Side Collision</td>\n",
       "      <td>Total Loss</td>\n",
       "      <td>Ambulance</td>\n",
       "      <td>S5</td>\n",
       "      <td>Riverwood</td>\n",
       "      <td>?</td>\n",
       "      <td>?</td>\n",
       "      <td>Nissan</td>\n",
       "      <td>Maxima</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1998-01-04</td>\n",
       "      <td>B</td>\n",
       "      <td>250/500</td>\n",
       "      <td>MALE</td>\n",
       "      <td>JD</td>\n",
       "      <td>craft-repair</td>\n",
       "      <td>polo</td>\n",
       "      <td>other-relative</td>\n",
       "      <td>2015-02-18</td>\n",
       "      <td>Multi-vehicle Collision</td>\n",
       "      <td>Side Collision</td>\n",
       "      <td>Minor Damage</td>\n",
       "      <td>Other</td>\n",
       "      <td>S5</td>\n",
       "      <td>Springfield</td>\n",
       "      <td>?</td>\n",
       "      <td>YES</td>\n",
       "      <td>Honda</td>\n",
       "      <td>Civic</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1996-02-06</td>\n",
       "      <td>B</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>FEMALE</td>\n",
       "      <td>High School</td>\n",
       "      <td>machine-op-inspct</td>\n",
       "      <td>skydiving</td>\n",
       "      <td>wife</td>\n",
       "      <td>2015-01-18</td>\n",
       "      <td>Single Vehicle Collision</td>\n",
       "      <td>Side Collision</td>\n",
       "      <td>Total Loss</td>\n",
       "      <td>Police</td>\n",
       "      <td>S3</td>\n",
       "      <td>Northbend</td>\n",
       "      <td>?</td>\n",
       "      <td>NO</td>\n",
       "      <td>Jeep</td>\n",
       "      <td>Wrangler</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2008-11-14</td>\n",
       "      <td>A</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>MALE</td>\n",
       "      <td>JD</td>\n",
       "      <td>transport-moving</td>\n",
       "      <td>video-games</td>\n",
       "      <td>own-child</td>\n",
       "      <td>2015-02-02</td>\n",
       "      <td>Multi-vehicle Collision</td>\n",
       "      <td>Front Collision</td>\n",
       "      <td>Major Damage</td>\n",
       "      <td>Fire</td>\n",
       "      <td>S3</td>\n",
       "      <td>Northbend</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>Suburu</td>\n",
       "      <td>Legacy</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2002-01-08</td>\n",
       "      <td>A</td>\n",
       "      <td>100/300</td>\n",
       "      <td>FEMALE</td>\n",
       "      <td>MD</td>\n",
       "      <td>craft-repair</td>\n",
       "      <td>video-games</td>\n",
       "      <td>own-child</td>\n",
       "      <td>2015-02-09</td>\n",
       "      <td>Multi-vehicle Collision</td>\n",
       "      <td>Rear Collision</td>\n",
       "      <td>Total Loss</td>\n",
       "      <td>Fire</td>\n",
       "      <td>S2</td>\n",
       "      <td>Northbend</td>\n",
       "      <td>YES</td>\n",
       "      <td>YES</td>\n",
       "      <td>Ford</td>\n",
       "      <td>F150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>1999-08-18</td>\n",
       "      <td>B</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>FEMALE</td>\n",
       "      <td>College</td>\n",
       "      <td>prof-specialty</td>\n",
       "      <td>kayaking</td>\n",
       "      <td>not-in-family</td>\n",
       "      <td>2015-01-14</td>\n",
       "      <td>Parked Car</td>\n",
       "      <td>?</td>\n",
       "      <td>Trivial Damage</td>\n",
       "      <td>None</td>\n",
       "      <td>S3</td>\n",
       "      <td>Arlington</td>\n",
       "      <td>NO</td>\n",
       "      <td>YES</td>\n",
       "      <td>Dodge</td>\n",
       "      <td>Neon</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>2009-12-23</td>\n",
       "      <td>C</td>\n",
       "      <td>250/500</td>\n",
       "      <td>MALE</td>\n",
       "      <td>MD</td>\n",
       "      <td>adm-clerical</td>\n",
       "      <td>movies</td>\n",
       "      <td>unmarried</td>\n",
       "      <td>2015-02-09</td>\n",
       "      <td>Multi-vehicle Collision</td>\n",
       "      <td>Side Collision</td>\n",
       "      <td>Total Loss</td>\n",
       "      <td>Fire</td>\n",
       "      <td>S3</td>\n",
       "      <td>Columbus</td>\n",
       "      <td>?</td>\n",
       "      <td>YES</td>\n",
       "      <td>Jeep</td>\n",
       "      <td>Grand Cherokee</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>1999-04-08</td>\n",
       "      <td>C</td>\n",
       "      <td>500/1000</td>\n",
       "      <td>FEMALE</td>\n",
       "      <td>Associate</td>\n",
       "      <td>other-service</td>\n",
       "      <td>hiking</td>\n",
       "      <td>not-in-family</td>\n",
       "      <td>2014-12-21</td>\n",
       "      <td>Single Vehicle Collision</td>\n",
       "      <td>Rear Collision</td>\n",
       "      <td>Minor Damage</td>\n",
       "      <td>Police</td>\n",
       "      <td>S1</td>\n",
       "      <td>Hillsdale</td>\n",
       "      <td>YES</td>\n",
       "      <td>?</td>\n",
       "      <td>Dodge</td>\n",
       "      <td>RAM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>2010-09-08</td>\n",
       "      <td>C</td>\n",
       "      <td>100/300</td>\n",
       "      <td>FEMALE</td>\n",
       "      <td>MD</td>\n",
       "      <td>protective-serv</td>\n",
       "      <td>hiking</td>\n",
       "      <td>unmarried</td>\n",
       "      <td>2015-01-27</td>\n",
       "      <td>Multi-vehicle Collision</td>\n",
       "      <td>Side Collision</td>\n",
       "      <td>Minor Damage</td>\n",
       "      <td>Fire</td>\n",
       "      <td>S4</td>\n",
       "      <td>Springfield</td>\n",
       "      <td>YES</td>\n",
       "      <td>?</td>\n",
       "      <td>Nissan</td>\n",
       "      <td>Maxima</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>1990-09-27</td>\n",
       "      <td>C</td>\n",
       "      <td>100/300</td>\n",
       "      <td>MALE</td>\n",
       "      <td>Masters</td>\n",
       "      <td>protective-serv</td>\n",
       "      <td>dancing</td>\n",
       "      <td>other-relative</td>\n",
       "      <td>2015-01-29</td>\n",
       "      <td>Single Vehicle Collision</td>\n",
       "      <td>Front Collision</td>\n",
       "      <td>Minor Damage</td>\n",
       "      <td>Ambulance</td>\n",
       "      <td>S7</td>\n",
       "      <td>Hillsdale</td>\n",
       "      <td>NO</td>\n",
       "      <td>YES</td>\n",
       "      <td>Honda</td>\n",
       "      <td>Civic</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 19 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    policy_bind_date policy_state policy_csl insured_sex  \\\n",
       "0         2013-08-21            C   500/1000      FEMALE   \n",
       "1         1998-01-04            B    250/500        MALE   \n",
       "2         1996-02-06            B   500/1000      FEMALE   \n",
       "3         2008-11-14            A   500/1000        MALE   \n",
       "4         2002-01-08            A    100/300      FEMALE   \n",
       "..               ...          ...        ...         ...   \n",
       "995       1999-08-18            B   500/1000      FEMALE   \n",
       "996       2009-12-23            C    250/500        MALE   \n",
       "997       1999-04-08            C   500/1000      FEMALE   \n",
       "998       2010-09-08            C    100/300      FEMALE   \n",
       "999       1990-09-27            C    100/300        MALE   \n",
       "\n",
       "    insured_education_level insured_occupation insured_hobbies  \\\n",
       "0                   Masters    protective-serv         reading   \n",
       "1                        JD       craft-repair            polo   \n",
       "2               High School  machine-op-inspct       skydiving   \n",
       "3                        JD   transport-moving     video-games   \n",
       "4                        MD       craft-repair     video-games   \n",
       "..                      ...                ...             ...   \n",
       "995                 College     prof-specialty        kayaking   \n",
       "996                      MD       adm-clerical          movies   \n",
       "997               Associate      other-service          hiking   \n",
       "998                      MD    protective-serv          hiking   \n",
       "999                 Masters    protective-serv         dancing   \n",
       "\n",
       "    insured_relationship incident_date             incident_type  \\\n",
       "0          not-in-family    2014-12-22  Single Vehicle Collision   \n",
       "1         other-relative    2015-02-18   Multi-vehicle Collision   \n",
       "2                   wife    2015-01-18  Single Vehicle Collision   \n",
       "3              own-child    2015-02-02   Multi-vehicle Collision   \n",
       "4              own-child    2015-02-09   Multi-vehicle Collision   \n",
       "..                   ...           ...                       ...   \n",
       "995        not-in-family    2015-01-14                Parked Car   \n",
       "996            unmarried    2015-02-09   Multi-vehicle Collision   \n",
       "997        not-in-family    2014-12-21  Single Vehicle Collision   \n",
       "998            unmarried    2015-01-27   Multi-vehicle Collision   \n",
       "999       other-relative    2015-01-29  Single Vehicle Collision   \n",
       "\n",
       "      collision_type incident_severity authorities_contacted incident_state  \\\n",
       "0     Side Collision        Total Loss             Ambulance             S5   \n",
       "1     Side Collision      Minor Damage                 Other             S5   \n",
       "2     Side Collision        Total Loss                Police             S3   \n",
       "3    Front Collision      Major Damage                  Fire             S3   \n",
       "4     Rear Collision        Total Loss                  Fire             S2   \n",
       "..               ...               ...                   ...            ...   \n",
       "995                ?    Trivial Damage                  None             S3   \n",
       "996   Side Collision        Total Loss                  Fire             S3   \n",
       "997   Rear Collision      Minor Damage                Police             S1   \n",
       "998   Side Collision      Minor Damage                  Fire             S4   \n",
       "999  Front Collision      Minor Damage             Ambulance             S7   \n",
       "\n",
       "    incident_city property_damage police_report_available auto_make  \\\n",
       "0       Riverwood               ?                       ?    Nissan   \n",
       "1     Springfield               ?                     YES     Honda   \n",
       "2       Northbend               ?                      NO      Jeep   \n",
       "3       Northbend             YES                     YES    Suburu   \n",
       "4       Northbend             YES                     YES      Ford   \n",
       "..            ...             ...                     ...       ...   \n",
       "995     Arlington              NO                     YES     Dodge   \n",
       "996      Columbus               ?                     YES      Jeep   \n",
       "997     Hillsdale             YES                       ?     Dodge   \n",
       "998   Springfield             YES                       ?    Nissan   \n",
       "999     Hillsdale              NO                     YES     Honda   \n",
       "\n",
       "         auto_model  \n",
       "0            Maxima  \n",
       "1             Civic  \n",
       "2          Wrangler  \n",
       "3            Legacy  \n",
       "4              F150  \n",
       "..              ...  \n",
       "995            Neon  \n",
       "996  Grand Cherokee  \n",
       "997             RAM  \n",
       "998          Maxima  \n",
       "999           Civic  \n",
       "\n",
       "[1000 rows x 19 columns]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[cat_columns]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['property_damage'] = data['property_damage'].map({'NO': 0, 'YES': 1, '?': 2})\n",
    "data['police_report_available'] = data['police_report_available'].map({'NO': 0, 'YES': 1, '?': 2})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pandas import Timestamp\n",
    "\n",
    "data['policy_bind_date'] = pd.to_datetime(data['policy_bind_date'])\n",
    "data['incident_date'] = pd.to_datetime(data['incident_date'])\n",
    "\n",
    "# 查看最大日期，最小日期\n",
    "data['policy_bind_date'].min() # 1990-01-08\n",
    "data['policy_bind_date'].max() # 2015-02-22\n",
    "\n",
    "data['incident_date'].min() # 2015-01-01\n",
    "data['incident_date'].max() # 2015-03-01\n",
    "\n",
    "base_date: Timestamp = data['policy_bind_date'].min()\n",
    "data['policy_bind_date_diff'] = (data['policy_bind_date'] - base_date).dt.days\n",
    "data['incident_date_diff'] = (data['incident_date'] - base_date).dt.days\n",
    "data['incident_date_policy_bind_date_diff'] = data['incident_date_diff'] - data['policy_bind_date_diff']\n",
    "\n",
    "data.drop(['policy_bind_date', 'incident_date'], axis=1, inplace=True)\n",
    "data.drop(['policy_id'], axis=1, inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>policy_state</th>\n",
       "      <th>policy_csl</th>\n",
       "      <th>insured_sex</th>\n",
       "      <th>insured_education_level</th>\n",
       "      <th>insured_occupation</th>\n",
       "      <th>insured_hobbies</th>\n",
       "      <th>insured_relationship</th>\n",
       "      <th>incident_type</th>\n",
       "      <th>collision_type</th>\n",
       "      <th>incident_severity</th>\n",
       "      <th>authorities_contacted</th>\n",
       "      <th>incident_state</th>\n",
       "      <th>incident_city</th>\n",
       "      <th>auto_make</th>\n",
       "      <th>auto_model</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>10</td>\n",
       "      <td>15</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>9</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>14</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>6</td>\n",
       "      <td>16</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>7</td>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>13</td>\n",
       "      <td>18</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>11</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>18</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>5</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>9</td>\n",
       "      <td>11</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>12</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>7</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>7</td>\n",
       "      <td>10</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>6</td>\n",
       "      <td>9</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "      <td>10</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>2</td>\n",
       "      <td>6</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     policy_state  policy_csl  insured_sex  insured_education_level  \\\n",
       "0               2           2            0                        5   \n",
       "1               1           1            1                        3   \n",
       "2               1           2            0                        2   \n",
       "3               0           2            1                        3   \n",
       "4               0           0            0                        4   \n",
       "..            ...         ...          ...                      ...   \n",
       "995             1           2            0                        1   \n",
       "996             2           1            1                        4   \n",
       "997             2           2            0                        0   \n",
       "998             2           0            0                        4   \n",
       "999             2           0            1                        5   \n",
       "\n",
       "     insured_occupation  insured_hobbies  insured_relationship  incident_type  \\\n",
       "0                    10               15                     1              2   \n",
       "1                     2               14                     2              0   \n",
       "2                     6               16                     5              2   \n",
       "3                    13               18                     3              0   \n",
       "4                     2               18                     3              0   \n",
       "..                  ...              ...                   ...            ...   \n",
       "995                   9               11                     1              1   \n",
       "996                   0               12                     4              0   \n",
       "997                   7               10                     1              2   \n",
       "998                  10               10                     4              0   \n",
       "999                  10                7                     2              2   \n",
       "\n",
       "     collision_type  incident_severity  authorities_contacted  incident_state  \\\n",
       "0                 3                  2                      0               4   \n",
       "1                 3                  1                      3               4   \n",
       "2                 3                  2                      4               2   \n",
       "3                 1                  0                      1               2   \n",
       "4                 2                  2                      1               1   \n",
       "..              ...                ...                    ...             ...   \n",
       "995               0                  3                      2               2   \n",
       "996               3                  2                      1               2   \n",
       "997               2                  1                      4               0   \n",
       "998               3                  1                      1               3   \n",
       "999               1                  1                      0               6   \n",
       "\n",
       "     incident_city  auto_make  auto_model  \n",
       "0                5          9          26  \n",
       "1                6          6          10  \n",
       "2                3          7          36  \n",
       "3                3         11          21  \n",
       "4                3          5          14  \n",
       "..             ...        ...         ...  \n",
       "995              0          4          27  \n",
       "996              1          7          17  \n",
       "997              2          4          30  \n",
       "998              6          9          26  \n",
       "999              2          6          10  \n",
       "\n",
       "[1000 rows x 15 columns]"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## 标签编码\n",
    "from sklearn.preprocessing import LabelEncoder\n",
    "cat_columns = data.select_dtypes(include='O').columns\n",
    "for col in cat_columns:\n",
    "    le = LabelEncoder()\n",
    "    data[col] = le.fit_transform(data[col])\n",
    "data[cat_columns]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 数据集切分\n",
    "train = data[data['fraud'].notnull()]\n",
    "test = data[data['fraud'].isnull()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[9.45512572e-01, 5.44874283e-02],\n",
       "       [2.82473773e-01, 7.17526227e-01],\n",
       "       [9.93965667e-01, 6.03433310e-03],\n",
       "       [9.76151564e-01, 2.38484363e-02],\n",
       "       [9.80256195e-01, 1.97438052e-02],\n",
       "       [9.14403023e-01, 8.55969772e-02],\n",
       "       [9.92182848e-01, 7.81715179e-03],\n",
       "       [9.95752551e-01, 4.24744905e-03],\n",
       "       [9.97857734e-01, 2.14226648e-03],\n",
       "       [9.87760328e-01, 1.22396721e-02],\n",
       "       [9.82583675e-01, 1.74163246e-02],\n",
       "       [9.94944970e-01, 5.05503008e-03],\n",
       "       [2.40580578e-01, 7.59419422e-01],\n",
       "       [9.94618068e-01, 5.38193197e-03],\n",
       "       [9.93408223e-01, 6.59177664e-03],\n",
       "       [6.73835883e-01, 3.26164117e-01],\n",
       "       [9.77552932e-01, 2.24470682e-02],\n",
       "       [9.90247497e-01, 9.75250283e-03],\n",
       "       [4.04842173e-02, 9.59515783e-01],\n",
       "       [9.90730834e-01, 9.26916620e-03],\n",
       "       [9.88710210e-01, 1.12897903e-02],\n",
       "       [9.40698501e-01, 5.93014990e-02],\n",
       "       [1.80777338e-01, 8.19222662e-01],\n",
       "       [9.69550179e-01, 3.04498213e-02],\n",
       "       [9.88685801e-01, 1.13141994e-02],\n",
       "       [2.12889198e-01, 7.87110802e-01],\n",
       "       [9.96487685e-01, 3.51231514e-03],\n",
       "       [9.96884461e-01, 3.11553853e-03],\n",
       "       [4.99605699e-01, 5.00394301e-01],\n",
       "       [9.96129107e-01, 3.87089331e-03],\n",
       "       [4.20715961e-01, 5.79284039e-01],\n",
       "       [9.89623766e-01, 1.03762342e-02],\n",
       "       [2.54166010e-02, 9.74583399e-01],\n",
       "       [9.84981839e-01, 1.50181609e-02],\n",
       "       [9.87350072e-01, 1.26499281e-02],\n",
       "       [9.83336246e-01, 1.66637544e-02],\n",
       "       [1.32152061e-01, 8.67847939e-01],\n",
       "       [9.96588376e-01, 3.41162415e-03],\n",
       "       [9.91953279e-01, 8.04672111e-03],\n",
       "       [9.97897826e-01, 2.10217393e-03],\n",
       "       [8.91252781e-02, 9.10874722e-01],\n",
       "       [9.94004300e-01, 5.99570004e-03],\n",
       "       [9.97577072e-01, 2.42292836e-03],\n",
       "       [9.96318540e-01, 3.68146008e-03],\n",
       "       [9.06262390e-01, 9.37376096e-02],\n",
       "       [9.93839991e-01, 6.16000904e-03],\n",
       "       [9.83808701e-01, 1.61912989e-02],\n",
       "       [9.92657102e-01, 7.34289768e-03],\n",
       "       [9.04907442e-02, 9.09509256e-01],\n",
       "       [9.94547231e-01, 5.45276866e-03],\n",
       "       [9.93671234e-01, 6.32876633e-03],\n",
       "       [9.94529799e-01, 5.47020132e-03],\n",
       "       [9.95110693e-01, 4.88930674e-03],\n",
       "       [4.42298033e-01, 5.57701967e-01],\n",
       "       [6.65726502e-01, 3.34273498e-01],\n",
       "       [9.94659441e-01, 5.34055926e-03],\n",
       "       [9.87421354e-01, 1.25786465e-02],\n",
       "       [1.57174330e-01, 8.42825670e-01],\n",
       "       [9.76996183e-01, 2.30038169e-02],\n",
       "       [4.40825893e-01, 5.59174107e-01],\n",
       "       [9.93618848e-01, 6.38115178e-03],\n",
       "       [9.87754372e-01, 1.22456277e-02],\n",
       "       [9.77435941e-01, 2.25640586e-02],\n",
       "       [1.35569795e-01, 8.64430205e-01],\n",
       "       [9.93975450e-01, 6.02454975e-03],\n",
       "       [9.81943546e-01, 1.80564536e-02],\n",
       "       [1.27512709e-01, 8.72487291e-01],\n",
       "       [4.06816407e-02, 9.59318359e-01],\n",
       "       [9.91906401e-01, 8.09359944e-03],\n",
       "       [9.90248353e-01, 9.75164716e-03],\n",
       "       [9.92687875e-01, 7.31212517e-03],\n",
       "       [9.75579239e-01, 2.44207611e-02],\n",
       "       [3.36084086e-01, 6.63915914e-01],\n",
       "       [2.97747033e-01, 7.02252967e-01],\n",
       "       [9.98914489e-01, 1.08551058e-03],\n",
       "       [9.97287010e-01, 2.71298989e-03],\n",
       "       [9.87340825e-01, 1.26591748e-02],\n",
       "       [9.99229721e-01, 7.70278791e-04],\n",
       "       [1.64400724e-01, 8.35599276e-01],\n",
       "       [9.91724919e-01, 8.27508089e-03],\n",
       "       [9.87266079e-01, 1.27339206e-02],\n",
       "       [9.75660223e-01, 2.43397773e-02],\n",
       "       [7.43682041e-01, 2.56317959e-01],\n",
       "       [9.52287754e-01, 4.77122460e-02],\n",
       "       [9.92296310e-01, 7.70369021e-03],\n",
       "       [9.97518435e-01, 2.48156544e-03],\n",
       "       [9.84822380e-01, 1.51776195e-02],\n",
       "       [9.96706031e-01, 3.29396922e-03],\n",
       "       [9.87511425e-01, 1.24885745e-02],\n",
       "       [2.48082217e-01, 7.51917783e-01],\n",
       "       [9.95701148e-01, 4.29885247e-03],\n",
       "       [1.75833896e-01, 8.24166104e-01],\n",
       "       [7.76006842e-02, 9.22399316e-01],\n",
       "       [9.92670470e-01, 7.32952970e-03],\n",
       "       [9.97128215e-01, 2.87178506e-03],\n",
       "       [9.79908458e-01, 2.00915417e-02],\n",
       "       [9.87021297e-01, 1.29787033e-02],\n",
       "       [9.89360581e-01, 1.06394187e-02],\n",
       "       [7.76148285e-01, 2.23851715e-01],\n",
       "       [9.90548203e-01, 9.45179658e-03],\n",
       "       [9.79195399e-01, 2.08046008e-02],\n",
       "       [4.82063094e-01, 5.17936906e-01],\n",
       "       [9.90301066e-01, 9.69893400e-03],\n",
       "       [9.97421299e-01, 2.57870123e-03],\n",
       "       [9.98939542e-01, 1.06045823e-03],\n",
       "       [2.11938048e-01, 7.88061952e-01],\n",
       "       [7.62277399e-01, 2.37722601e-01],\n",
       "       [2.51512231e-01, 7.48487769e-01],\n",
       "       [9.57839250e-01, 4.21607498e-02],\n",
       "       [9.83969687e-01, 1.60303127e-02],\n",
       "       [9.97081549e-01, 2.91845116e-03],\n",
       "       [9.94323316e-01, 5.67668380e-03],\n",
       "       [9.92818112e-01, 7.18188786e-03],\n",
       "       [9.97357246e-01, 2.64275387e-03],\n",
       "       [9.93395207e-01, 6.60479266e-03],\n",
       "       [6.73657672e-01, 3.26342328e-01],\n",
       "       [3.04733550e-02, 9.69526645e-01],\n",
       "       [9.93981058e-01, 6.01894160e-03],\n",
       "       [2.41826643e-02, 9.75817336e-01],\n",
       "       [9.96970483e-01, 3.02951665e-03],\n",
       "       [9.96969561e-01, 3.03043946e-03],\n",
       "       [9.67780490e-01, 3.22195097e-02],\n",
       "       [1.95122308e-01, 8.04877692e-01],\n",
       "       [5.73293174e-01, 4.26706826e-01],\n",
       "       [9.56559556e-01, 4.34404442e-02],\n",
       "       [1.27101590e-01, 8.72898410e-01],\n",
       "       [9.94386161e-01, 5.61383877e-03],\n",
       "       [9.92817176e-01, 7.18282411e-03],\n",
       "       [2.22596183e-01, 7.77403817e-01],\n",
       "       [9.97285190e-01, 2.71480969e-03],\n",
       "       [9.91554629e-01, 8.44537088e-03],\n",
       "       [4.17724974e-01, 5.82275026e-01],\n",
       "       [9.91999986e-01, 8.00001367e-03],\n",
       "       [9.94964556e-01, 5.03544427e-03],\n",
       "       [9.94795498e-01, 5.20450202e-03],\n",
       "       [9.96463373e-01, 3.53662678e-03],\n",
       "       [7.69709115e-01, 2.30290885e-01],\n",
       "       [4.16423432e-01, 5.83576568e-01],\n",
       "       [3.58934570e-01, 6.41065430e-01],\n",
       "       [9.91872863e-01, 8.12713740e-03],\n",
       "       [9.40258026e-01, 5.97419743e-02],\n",
       "       [9.77238293e-01, 2.27617075e-02],\n",
       "       [8.40252276e-02, 9.15974772e-01],\n",
       "       [6.14388005e-01, 3.85611995e-01],\n",
       "       [1.61256049e-01, 8.38743951e-01],\n",
       "       [1.05437633e-01, 8.94562367e-01],\n",
       "       [9.92252174e-01, 7.74782649e-03],\n",
       "       [9.96073288e-01, 3.92671170e-03],\n",
       "       [9.47828983e-01, 5.21710172e-02],\n",
       "       [9.94442755e-01, 5.55724494e-03],\n",
       "       [9.94947940e-01, 5.05205965e-03],\n",
       "       [2.42905474e-01, 7.57094526e-01],\n",
       "       [9.29760834e-02, 9.07023917e-01],\n",
       "       [3.40573399e-01, 6.59426601e-01],\n",
       "       [9.92987391e-01, 7.01260866e-03],\n",
       "       [9.95334736e-01, 4.66526436e-03],\n",
       "       [2.41407657e-01, 7.58592343e-01],\n",
       "       [9.85540235e-01, 1.44597655e-02],\n",
       "       [9.43958888e-01, 5.60411120e-02],\n",
       "       [9.86004579e-01, 1.39954207e-02],\n",
       "       [2.94467511e-01, 7.05532489e-01],\n",
       "       [9.90363268e-01, 9.63673179e-03],\n",
       "       [3.27745295e-01, 6.72254705e-01],\n",
       "       [6.66257981e-02, 9.33374202e-01],\n",
       "       [3.19919177e-01, 6.80080823e-01],\n",
       "       [3.87770147e-01, 6.12229853e-01],\n",
       "       [9.97294663e-01, 2.70533672e-03],\n",
       "       [9.90669591e-01, 9.33040891e-03],\n",
       "       [1.13411948e-01, 8.86588052e-01],\n",
       "       [9.92537191e-01, 7.46280935e-03],\n",
       "       [9.97074094e-01, 2.92590624e-03],\n",
       "       [9.44533460e-01, 5.54665404e-02],\n",
       "       [7.14038534e-01, 2.85961466e-01],\n",
       "       [3.14936731e-01, 6.85063269e-01],\n",
       "       [9.93446098e-01, 6.55390203e-03],\n",
       "       [1.24712374e-01, 8.75287626e-01],\n",
       "       [9.96810084e-01, 3.18991600e-03],\n",
       "       [9.78486442e-01, 2.15135580e-02],\n",
       "       [9.90389125e-01, 9.61087526e-03],\n",
       "       [9.97586708e-01, 2.41329204e-03],\n",
       "       [9.91663653e-01, 8.33634698e-03],\n",
       "       [9.97382883e-01, 2.61711660e-03],\n",
       "       [9.89259718e-01, 1.07402819e-02],\n",
       "       [9.95469247e-01, 4.53075323e-03],\n",
       "       [9.83307032e-01, 1.66929681e-02],\n",
       "       [4.11688307e-01, 5.88311693e-01],\n",
       "       [9.74789801e-01, 2.52101985e-02],\n",
       "       [1.45645547e-01, 8.54354453e-01],\n",
       "       [9.60887748e-01, 3.91122524e-02],\n",
       "       [9.84689543e-01, 1.53104573e-02],\n",
       "       [9.78179112e-01, 2.18208885e-02],\n",
       "       [9.91187494e-01, 8.81250630e-03],\n",
       "       [9.89845148e-01, 1.01548518e-02],\n",
       "       [6.99401852e-02, 9.30059815e-01],\n",
       "       [3.68194045e-01, 6.31805955e-01],\n",
       "       [9.98194052e-01, 1.80594773e-03],\n",
       "       [9.88169416e-01, 1.18305835e-02],\n",
       "       [9.94968590e-01, 5.03140965e-03],\n",
       "       [9.96236946e-01, 3.76305434e-03],\n",
       "       [5.96823943e-02, 9.40317606e-01],\n",
       "       [9.91681111e-01, 8.31888861e-03],\n",
       "       [9.95168052e-01, 4.83194775e-03],\n",
       "       [6.49833033e-02, 9.35016697e-01],\n",
       "       [8.61113786e-01, 1.38886214e-01],\n",
       "       [9.90214417e-01, 9.78558268e-03],\n",
       "       [9.96378903e-01, 3.62109733e-03],\n",
       "       [9.83684490e-01, 1.63155104e-02],\n",
       "       [9.87879380e-01, 1.21206201e-02],\n",
       "       [9.58061182e-01, 4.19388175e-02],\n",
       "       [9.96354399e-01, 3.64560140e-03],\n",
       "       [9.93213173e-01, 6.78682658e-03],\n",
       "       [9.93823326e-01, 6.17667426e-03],\n",
       "       [9.98722588e-01, 1.27741158e-03],\n",
       "       [9.94613919e-01, 5.38608143e-03],\n",
       "       [5.21094630e-01, 4.78905370e-01],\n",
       "       [9.60277688e-01, 3.97223120e-02],\n",
       "       [2.77720793e-01, 7.22279207e-01],\n",
       "       [9.99094015e-01, 9.05984926e-04],\n",
       "       [9.94670131e-01, 5.32986869e-03],\n",
       "       [4.49165731e-01, 5.50834269e-01],\n",
       "       [7.80760049e-01, 2.19239951e-01],\n",
       "       [8.86521495e-01, 1.13478505e-01],\n",
       "       [9.86887125e-01, 1.31128750e-02],\n",
       "       [9.59590791e-01, 4.04092088e-02],\n",
       "       [9.32217648e-01, 6.77823520e-02],\n",
       "       [4.96834850e-01, 5.03165150e-01],\n",
       "       [9.92290358e-01, 7.70964192e-03],\n",
       "       [9.62940213e-01, 3.70597868e-02],\n",
       "       [1.09728319e-02, 9.89027168e-01],\n",
       "       [9.08900624e-01, 9.10993756e-02],\n",
       "       [9.84243991e-01, 1.57560094e-02],\n",
       "       [9.25712363e-01, 7.42876369e-02],\n",
       "       [9.94448831e-01, 5.55116868e-03],\n",
       "       [9.94195679e-01, 5.80432101e-03],\n",
       "       [5.56061435e-01, 4.43938565e-01],\n",
       "       [4.37779932e-02, 9.56222007e-01],\n",
       "       [9.95974629e-01, 4.02537077e-03],\n",
       "       [9.94053834e-01, 5.94616573e-03],\n",
       "       [9.94791710e-01, 5.20829004e-03],\n",
       "       [9.97243884e-01, 2.75611587e-03],\n",
       "       [7.66301873e-01, 2.33698127e-01],\n",
       "       [9.93657702e-01, 6.34229829e-03],\n",
       "       [9.93864781e-01, 6.13521938e-03],\n",
       "       [9.93608499e-01, 6.39150059e-03],\n",
       "       [9.94297142e-01, 5.70285832e-03],\n",
       "       [8.34474894e-01, 1.65525106e-01],\n",
       "       [9.96277964e-01, 3.72203594e-03],\n",
       "       [9.90136375e-01, 9.86362483e-03],\n",
       "       [9.86513093e-01, 1.34869067e-02],\n",
       "       [9.96132356e-01, 3.86764396e-03],\n",
       "       [7.73591213e-01, 2.26408787e-01],\n",
       "       [2.41725672e-01, 7.58274328e-01],\n",
       "       [3.88708402e-01, 6.11291598e-01],\n",
       "       [9.96744867e-01, 3.25513279e-03],\n",
       "       [9.96293666e-01, 3.70633394e-03],\n",
       "       [9.84115598e-01, 1.58844015e-02],\n",
       "       [5.19166624e-01, 4.80833376e-01],\n",
       "       [9.80879071e-01, 1.91209286e-02],\n",
       "       [7.80129394e-02, 9.21987061e-01],\n",
       "       [8.75568696e-01, 1.24431304e-01],\n",
       "       [3.51067882e-02, 9.64893212e-01],\n",
       "       [9.45449740e-01, 5.45502601e-02],\n",
       "       [7.88229278e-01, 2.11770722e-01],\n",
       "       [9.96753670e-01, 3.24633004e-03],\n",
       "       [9.90108860e-01, 9.89114036e-03],\n",
       "       [9.87276389e-01, 1.27236112e-02],\n",
       "       [9.93173233e-01, 6.82676658e-03],\n",
       "       [9.96274002e-01, 3.72599840e-03],\n",
       "       [9.95473548e-01, 4.52645158e-03],\n",
       "       [9.91069485e-01, 8.93051524e-03],\n",
       "       [1.28760315e-01, 8.71239685e-01],\n",
       "       [8.42456182e-01, 1.57543818e-01],\n",
       "       [9.94213932e-01, 5.78606763e-03],\n",
       "       [8.33190631e-01, 1.66809369e-01],\n",
       "       [6.41573314e-01, 3.58426686e-01],\n",
       "       [9.86495854e-01, 1.35041465e-02],\n",
       "       [9.84220352e-01, 1.57796481e-02],\n",
       "       [9.93220882e-01, 6.77911783e-03],\n",
       "       [2.01234634e-02, 9.79876537e-01],\n",
       "       [9.95069283e-01, 4.93071724e-03],\n",
       "       [9.83504150e-01, 1.64958505e-02],\n",
       "       [9.32087833e-01, 6.79121674e-02],\n",
       "       [9.86994610e-01, 1.30053897e-02],\n",
       "       [2.90306459e-01, 7.09693541e-01],\n",
       "       [4.41552118e-01, 5.58447882e-01],\n",
       "       [9.98949412e-01, 1.05058832e-03],\n",
       "       [2.80764190e-01, 7.19235810e-01],\n",
       "       [9.51064259e-01, 4.89357407e-02],\n",
       "       [8.04345641e-01, 1.95654359e-01],\n",
       "       [2.19266181e-02, 9.78073382e-01],\n",
       "       [9.59170371e-01, 4.08296287e-02],\n",
       "       [5.82332221e-02, 9.41766778e-01],\n",
       "       [5.01139737e-01, 4.98860263e-01],\n",
       "       [9.95661382e-01, 4.33861786e-03],\n",
       "       [6.08262862e-01, 3.91737138e-01],\n",
       "       [9.94965319e-01, 5.03468063e-03],\n",
       "       [9.94962679e-01, 5.03732092e-03],\n",
       "       [9.96830618e-01, 3.16938159e-03],\n",
       "       [9.90193503e-01, 9.80649715e-03],\n",
       "       [9.91544053e-01, 8.45594716e-03]])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import lightgbm as lgb\n",
    "model_lgb = lgb.LGBMClassifier(\n",
    "            num_leaves=2**5-1, reg_alpha=0.25, reg_lambda=0.25, objective='binary',\n",
    "            max_depth=-1, learning_rate=0.005, min_child_samples=3, random_state=2022,\n",
    "            n_estimators=2000, subsample=1, colsample_bytree=1,\n",
    "        )\n",
    "# 模型训练\n",
    "model_lgb.fit(train.drop(['fraud'], axis=1), train['fraud'])\n",
    "# AUC评测： 以proba进行提交，结果会更好\n",
    "y_pred = model_lgb.predict_proba(test.drop(['fraud'], axis=1))\n",
    "y_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.25857142857142856"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 25.8%\n",
    "train['fraud'].mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "result = pd.read_csv('./tianchi-dataset/submission.csv')\n",
    "result['fraud'] = y_pred[:, 1]\n",
    "result.to_csv('./tianchi-dataset/baseline.csv', index=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.10.4 ('env': venv)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.6"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "e6a44bc4ae6224bc4bc7b3a89841677b0124c79fe22f3d101cb1ffa8756f30f3"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
